<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title></title>
<jsp:include page="../links.jsp"></jsp:include>
</head>
<body>
	<script type="text/javascript">
		var car_datagrid;
		var car_searchForm;
		var car_addDlg;
		var car_addForm;
		var car_updateDlg;
		var car_updateForm;
		$(function() {
			car_datagrid = $('#car_datagrid').datagrid({
				url : getRootPath() + '/admin/carAction/datagrid.do',
				title : '车次列表',
				iconCls : 'icon-save',
				pagination : true,
				rownumbers : true,
				selectOnCheck : true,
				checkOnSelect : false,
				pageSize : 10,
				pageList : [ 10, 20, 30, 40, 50 ],
				fit : true,
				fitColumns : true,
				nowarp : false,
				border : false,
				idField : 'carid',
				sortOrder : 'asc',
				columns : [ [ {
					title : '',
					field : '0',
					width : 100,
					checkbox : true
				}, {
					title : '编号',
					field : 'carid',
					width : 100,
					sortable : false
				}, {
					title : '发车地点',
					field : 'locationstart',
					width : 200,
				}, {
					title : '到达地点',
					field : 'locationend',
					width : 150
				}, {
					title : '发车时间',
					field : 'starttime',
					width : 100,
					formatter : function(starttime, row, index) {
						return starttime.substr(11, 5);
					}
				}, {
					title : '到达时间',
					field : 'endtime',
					width : 100,
					formatter : function(endtime, row, index) {
						return endtime.substr(11, 5);
					}
				} ] ],
				toolbar : [ {
					text : '添加',
					iconCls : 'icon-add',
					handler : function() {
						car_showAddDlg();
					}
				}, '-', {
					text : '修改',
					iconCls : 'icon-edit',
					handler : function() {
						car_showUpdateDlg();
					}
				}, '-', {
					text : '删除',
					iconCls : 'icon-remove',
					handler : function() {
						car_remove();
					}
				} ]
			});//datagrid end
			//过滤查询
			car_searchForm = $('#car_searchForm').form();
			car_doSearch = function() {
				//console.info(serializeObject(car_searchForm));
				car_datagrid.datagrid('load', serializeObject(car_searchForm));
			};
			//重置
			car_cleanSearch = function() {
				car_datagrid.datagrid('load', {});
				car_searchForm.find('input').val('');
			};
			//新增
			car_addDlg = $('#car_addDlg').dialog();
			car_addForm = $('#car_addForm').form();
			car_showAddDlg = function() {
				//$('#car_addForm input').val('');
				car_addDlg.dialog('open')
			};
			car_doAdd = function() {
				car_addForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/carAction/add.do',
					onSubmit : function(param) {
						if ($('#car_add_starttime').val() != null) {
							$('#car_add_starttime').val("1970-01-01 " + $('#car_add_starttime').val() + ":00");
						}
						if ($('#car_add_endtime').val() != null) {
							$('#car_add_endtime').val("1970-01-01 " + $('#car_add_endtime').val() + ":00");
						}
					},
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							car_addDlg.dialog('close');
							car_cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//修改
			car_updateDlg = $('#car_updateDlg').dialog();
			car_updateForm = $('#car_updateForm').form();
			car_showUpdateDlg = function() {
				var selectids = car_datagrid.datagrid('getChecked');
				if (selectids.length == 1) {
					car_updateDlg.dialog('open');
					$('#car_up_carid').val(selectids[0].carid);
					$('#car_up_starttime').val(selectids[0].starttime.substr(11, 5));
					$('#car_up_endtime').val(selectids[0].endtime.substr(11, 5));
				} else {
					$.messager.alert('提示', "请勾选一项");
				}
			};
			car_doUpdate = function() {
				car_updateForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/carAction/update.do?',
					onSubmit : function(param) {
						if ($('#car_up_starttime').val() != null) {
							$('#car_up_starttime').val("1970-01-01 " + $('#car_up_starttime').val() + ":00");
						}
						if ($('#car_up_endtime').val() != null) {
							$('#car_up_endtime').val("1970-01-01 " + $('#car_up_endtime').val() + ":00");
						}
					},
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							car_updateDlg.dialog('close');
							car_cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//删除
			car_remove = function() {
				var selectids = car_datagrid.datagrid('getChecked');
				var ids = [];
				if (selectids.length > 0) {
					$.messager.confirm('确认', '您是否要删除当前选中的项目？', function(r) {
						if (r) {
							for (var i = 0; i < selectids.length; i++) {
								ids.push(selectids[i].carid);
							}
							$.ajax({
								url : '${pageContext.request.contextPath}/admin/carAction/delete.do',
								data : {
									ids : ids.join(',')
								},
								dataType : 'json',
								success : function(r) {
									car_datagrid.datagrid('load');
									car_datagrid.datagrid('unselectAll');
									$.messager.show({
										title : '提示',
										msg : r.msg
									});
								}
							});
						}
					});
				} else {
					$.messager.alert('提示', "请最少勾选一项");
				}
			};
		});
	</script>
	<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'north',title:'模糊查询条件：(右边可折叠)'" style="height: 100%;">
			<form id="car_searchForm" method="post">
				<table style="width: 100%; height: 60%;">
					<tr>
						<th>发车地点:</th>
						<td><input name="car.locationstart" /></td>
						<th>到达地点:</th>
						<td><input name="car.locationend" />&nbsp;<a class="easyui-linkbutton" style="width: 25%"
							data-options="iconCls:'icon-search'" href="javascript:void(0)" onclick="car_doSearch();">查询</a><a
							class="easyui-linkbutton" style="width: 25%" data-options="iconCls:'icon-redo'"
							href="javascript:void(0)" onclick="car_cleanSearch();">清空</a></td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',title:''," style="overflow: hidden;">
			<table id="car_datagrid">
			</table>
		</div>
		<div id="car_addDlg"
			data-options="closed:true,modal:true,title:'添加车次',buttons:[
				{text : '添加',iconCls : 'icon-add',handler : function() {car_doAdd();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {car_addDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 350px; height: 210px;" align="center">
			<form id="car_addForm" method="post">
				<table>
					<tr>
						<th>发车地点:</th>
						<td><select class="easyui-combobox" name="car.locationstart" style="width: 173px"
							panelHeight="105px">
								<option value="校本部">校本部</option>
								<option value="旅顺校区一期">旅顺校区</option>
						</select></td>
					</tr>
					<tr>
						<th>到达地点:</th>
						<td><select class="easyui-combobox" name="car.locationend" style="width: 173px" panelHeight="105px">
								<option value="校本部">校本部</option>
								<option value="旅顺校区一期">旅顺校区</option>
								<option value="大连火车站">大连火车站</option>
						</select></td>
					</tr>
					<tr>
						<th>发车时间:</th>
						<td><input id="car_add_starttime" name="car.starttime"
							class="easyui-validatebox easyui-timespinner" type="text"
							data-options="required:true,min:'06:30',showSeconds:false" /></td>
					</tr>
					<tr>
						<th>到达时间:</th>
						<td><input id="car_add_endtime" name="car.endtime" class="easyui-validatebox easyui-timespinner"
							type="text" data-options="required:true,max:'19:30',showSeconds:false" /></td>
					</tr>
				</table>
			</form>
		</div>
		<div id="car_updateDlg"
			data-options="closed:true,modal:true,title:'修改失物信息',buttons:[
				{text : '修改',iconCls : 'icon-save',handler : function() {car_doUpdate();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {car_updateDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 350px; height: 230px;" align="center">
			<form id="car_updateForm" method="post">
				<table>
					<tr>
						<th>编号:</th>
						<td><input id="car_up_carid" name="car.carid" class="easyui-validatebox"
							data-options="required:true" readonly="readonly" /></td>
					</tr>
					<tr>
						<th>发车地点:</th>
						<td><select class="easyui-combobox" name="car.locationstart" style="width: 173px"
							panelHeight="105px">
								<option value="校本部">校本部</option>
								<option value="旅顺校区一期">旅顺校区</option>
						</select></td>
					</tr>
					<tr>
						<th>到达地点:</th>
						<td><select class="easyui-combobox" name="car.locationend" style="width: 173px" panelHeight="105px">
								<option value="校本部">校本部</option>
								<option value="旅顺校区一期">旅顺校区</option>
								<option value="大连火车站">大连火车站</option>
						</select></td>
					</tr>
					<tr>
						<th>发车时间:</th>
						<td><input id="car_up_starttime" name="car.starttime" class="easyui-validatebox easyui-timespinner"
							type="text" data-options="required:true,min:'06:30',showSeconds:false" /></td>
					</tr>
					<tr>
						<th>到达时间:</th>
						<td><input id="car_up_endtime" name="car.endtime" class="easyui-validatebox easyui-timespinner"
							type="text" data-options="required:true,max:'19:30',showSeconds:false" /></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>